#ifndef SIMPLEPROXYMODEL_H
#define SIMPLEPROXYMODEL_H



#include <ItemModel.h>



#include <QAbstractProxyModel>
#include <QStringList>



typedef QPersistentModelIndex SourceIndex;
typedef QPersistentModelIndex ProxyIndex;

typedef QMap<SourceIndex, ProxyIndex> IndexMap;
typedef QMapIterator<SourceIndex, ProxyIndex> IndexMapIterator;


class SimpleProxyModel : public QAbstractProxyModel
{
    Q_OBJECT

public:

    enum SimpleFilter
    {
        NoFilter = -1,

        SimpleFilter_FIRST = 0,
        RegExpFilter = SimpleFilter_FIRST,
        ContainsFilter,
        StartsWithFilter,
        EndsWithFilter,
        SimpleFilter_LAST = EndsWithFilter
    };

    SimpleProxyModel(QObject *parent = 0);

    // required from abstract item model
    virtual QModelIndex index(int row, int column, const QModelIndex &proxyParent) const;
    virtual QModelIndex parent(const QModelIndex &proxyChild) const;

    virtual int rowCount(const QModelIndex &proxyParent) const;
    virtual int columnCount(const QModelIndex &proxyParent) const;

    // required from abstract proxy model
    virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
    virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const;

    // optional from abstract item model
    virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;


    // custom source model implementation
    ItemModel* itemModel() const;
    void setItemModel(ItemModel* model);

    // custom implementation for shown columns
    void addField(const int& sourceField, const QString& fieldName = QString());

    // custom implementation for items added to this proxy
    void addExcludeFilter(const QString& idPattern, const int& filter = ContainsFilter);
    void addIncludeFilter(const QString& idPattern, const int& filter = EndsWithFilter);

    int excludeFilter(const QString& itemId) const;
    int includeFilter(const QString& itemId) const;


protected slots:

    // inherited from abstract model
    virtual void onRowsInserted(const QModelIndex& sourceParent, int start, int end);
    virtual void onRowsRemoved(const QModelIndex& sourceParent, int start, int end);

    // custom interface
    virtual void remap();
    virtual void mapChildren(const QModelIndex& sourceParent = QModelIndex(), int start = 0);
    virtual void mapIndex(const QModelIndex& sourceIndex);


protected:

    QAbstractItemModel* sourceModel() const;
    virtual void setSourceModel(QAbstractItemModel *sourceModel);


    IndexMap m_indexMap;
    QMap<int, QString> m_fields;


    QMap<QString, int> m_exclusions;
    QMap<QString, int> m_inclusions;


};



#endif // SIMPLEPROXYMODEL_H
